import optparse
import socketserver
import os,sys

# PATH=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# sys.path.append(PATH)
# print(sys.path)
# from FTP.FTP_server.src import Myserver
# from FTP.FTP_server.config import settings
from src import Myserver
from config import settings
class ArgvHandler():
    def __init__(self):
        self.op=optparse.OptionParser()
        # self.op.add_option("-s", "--s", dest="server")
        # self.op.add_option("-P", "--port", dest="port")
        options,args = self.op.parse_args()
        # print(options)# 绑定的信息
        # print(options.server)
        # print(options.port)
        # print("-------------")
        # print(args)# 未绑定的信息

        self.verify_args(options,args)

    def verify_args(self,options,args):
        # print(args[0])
        cmd = args[0]
        if hasattr(self,cmd):
            func = getattr(self,cmd)
            func()

    def start(self):
        print("server is working ..")
        s=socketserver.ThreadingTCPServer((settings.IP, settings.PORT), Myserver.ServerHandler)
        s.serve_forever()

    def help(self):
        print("okkokokokokokok")
    print('ok')


if __name__ == '__main__':
    ArgvHandler()